package org.kumas.sgrpc.common.threadlocal;

public class InternalRunnable implements Runnable{
    private final Runnable runnable;

    public InternalRunnable(Runnable runnable){
        this.runnable=runnable;
    }

    @Override
    public void run() {
        try{
            runnable.run();
        }finally {
            InternalThreadLocal.removeAll();
        }
    }

     static Runnable Wrap(Runnable runnable){
        return runnable instanceof InternalRunnable?runnable:new InternalRunnable(runnable);
    }
}